﻿using System;
using System.Collections.Generic;
using Ue.Qcdz.Domain.ContentTypes;


namespace Ue.Qcdz.Domain.TreeViews
{
    public class TreeViewService
    {
        #region 静态字段，方法

        private static ContentType treeViewContentType;

        static TreeViewService()
        {
            treeViewContentType = ContentTypeService.Instance.RegisterContentType(new ContentType(new Guid("cb7a061e-8c4d-445c-9c9e-a4ec90a4486e"))
            {
                Name = "树形结构",
                Description = "树型结构控制模块"
            });
        }


        private static class TreeViewServiceHolder
        {
            public static TreeViewService service = new TreeViewService();
        }

        public static TreeViewService Instance
        {
            get { return TreeViewServiceHolder.service; }
        }

        #endregion

        private ITreeViewRepository repository;

        private TreeViewService()
        {
            this.repository = Ue.Infrastructure.RepositoryFramework.RepositoryFactory.GetRepository<ITreeViewRepository, TreeView>();
        }

        public TreeView RegisterTreeView(TreeView treeView)
        {
            if (!this.repository.Contains(treeView))
            {
                this.repository.Add(treeView);
            }

            return this.repository[treeView.Key];
        }

        public ContentType ContentType
        {
            get { return TreeViewService.treeViewContentType; }
        }
    }
}
